<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>DNSLOG</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body style="background-color: #f1f1f1; padding-bottom: 0;font-family: Tahoma,Arial,Hiragino Sans GB,simsun,sans-serif">

<div th:insert="~{mainheader :: nav}"></div>

<div class="container" style="margin-top: 60px" data-example-id="simple-table">

    <div class="row" style="margin-top: 10px">
        <div class="col-md-2"><p style="font-size:20px;" th:text="'总记录数: '+${dnslogList.size()}"></p></div>
        <div class="col-md-1">
            <button type="button" class="btn btn-danger btn-sm" onclick="delAll()">删除所有</button>
        </div>
    </div>
    <table class="table" style="margin-top: 10px">
        <thead>
        <tr>
            <th>#</th>
            <th>Host</th>
            <th>IP</th>
            <th>Type</th>
            <th>Time</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="dnslog,dnslogStat:${dnslogList}">
            <td th:text="${dnslogStat.index+1}"></td>
            <td th:text="${dnslog['host']}"></td>
            <td th:text="${dnslog['ip']}"></td>
            <td th:text="${dnslog['type']}"></td>
            <td th:text="${dnslog['time']}"></td>
            <td>
                <button type="button" class="btn btn-danger btn-sm" th:id="${dnslog['id']}" onclick="delOne(this.id)">
                    删除
                </button>
            </td>
        </tr>
        </tbody>
    </table>
</div>

</body>
<script>
    function delOne(id) {
        $.ajax({
            type: "post",
            url: "/dnslog/delete",
            data: {
                "id": id
            },
            dataType: "json",
            success: function (response) {
                if (response.status === true) {
                    location.reload();
                } else {
                    alert("删除失败");
                }
            },
            error: function (response) {
                alert("删除失败");
            }
        });
    }

    function delAll() {
        $.ajax({
            type: "get",
            url: "/dnslog/delete_all",
            dataType: "json",
            success: function (response) {
                if (response.status === true) {
                    location.reload();
                } else {
                    alert("删除失败");
                }
            },
            error: function (response) {
                alert("删除失败");
            }
        });
    }
</script>

</html>
